package com.drug.mingkang.permission.controller;

import com.drug.mingkang.permission.model.PerRole;
import com.drug.mingkang.permission.model.PerRoleModule;
import com.drug.mingkang.permission.model.vo.PerRoleVo;
import com.drug.mingkang.permission.service.PerRoleModuleService;
import com.drug.mingkang.permission.service.PerRoleService;
import com.drug.mingkang.utils.AuditStatus;
import com.drug.mingkang.utils.ResponseMessage;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色表(PerRole)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:14
 */
@RestController
@RequestMapping("perRole")
public class PerRoleController {
    /**
     * 服务对象
     */
    @Resource
    private PerRoleService perRoleService;

    /**
     * 查询所有角色
     * @return
     */
    @ResponseBody
    @PostMapping("/showAllRole")
    public  List<PerRole> showAllRole(){
        return perRoleService.queryAll();
    }

    /**
     * 批量删除角色
     * @param RoleIdAll
     * @return
     */
    @ApiOperation(value = "批量删除角色", notes = "输入角色id数组", httpMethod = "POST", response = ResponseMessage.class)
    @PostMapping("/deleteAllRole")
    @ResponseBody
    public ResponseMessage deleteAllRole(String[] RoleIdAll){
        System.out.println("RoleIdArr.toString() = " + RoleIdAll.toString());
        return perRoleService.deleteAllById(RoleIdAll);
    }

    /**
     * 删除角色
     * @param roleId
     * @return
     */
    @ApiOperation(value = "删除角色", notes = "输入角色id", httpMethod = "POST", response = ResponseMessage.class)
    @ResponseBody
    @PostMapping("/deleteRole")
    public ResponseMessage deleteRole (Integer roleId){
        return perRoleService.deleteById(roleId);
    }


    /**
     * 角色增加 编辑
     * @param perRole
     * @param session
     * @return
     */
    @ApiOperation(value = "角色增加 编辑", notes = "输入角色信息", httpMethod = "POST", response = ResponseMessage.class)
    @PostMapping("/addOrUpdateRole")
    @ResponseBody
    public ResponseMessage addOrUpdateRole(PerRole perRole, HttpSession session) {
        return perRoleService.insertAndEdit(perRole,session);
    }


    /**
     * 通过主键查询单条数据
     * 根据所编辑的角色iD查询角色模块表里面的所有模块Id
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据所编辑的角色iD查询角色模块表里面的所有模块Id", notes = "输入角色id", httpMethod = "GET", response = PerRole.class)
    @GetMapping("/findById/{id}")
    @ResponseBody
    public PerRole findById(@PathVariable("id") Integer id) {
        return perRoleService.queryById(id);
    }


    /**
     * 查询所有角色
     * @return
     */
    @ApiOperation(value = "查询所有角色", notes = "输入查询条件", httpMethod = "GET", response = Map.class)
    @GetMapping("/showListRole")
    @ResponseBody
    public Map<String, Object> showListModule(PerRoleVo perRoleVo){
        Map<String, Object> map = perRoleService.queryAllByLimit(perRoleVo);
        return map;
    }
}